
using System;
using System.Linq;
using System.Collections.Generic;
using BLToolkit.DataAccess;
using BLToolkit.Mapping;
using BLToolkit.Data.Linq;
namespace Core
{
    [TableName("tblQuaTrinhTangLuong")]
    public class QuaTrinhTangLuong
    {
        [Identity, PrimaryKey(1)]
        [MapField("MaQTTangLuong")]
        public int ID { get; set; }
        public DateTime? TuNgay { get; set; }
        public DateTime? DenNgay { get; set; }
        public string PhanLoai { get; set; }


        // FK_tblCanBo_TangLuong_tblQTTangLuong
        [Association(ThisKey = "MaQTTangLuong", OtherKey = "MaQTTangLuong", CanBeNull = true)]
        public List<CanBoTangLuong> CanBo_TangLuongs { get; set; }

        public static IQueryable<QuaTrinhTangLuong> QTTangLuongs
        {
            get
            {
                using (var db = new DataContext())
                {
                    return db.GetTable<QuaTrinhTangLuong>();
                }
            }
        }
        public static List<QuaTrinhTangLuong> All()
        {
            return QTTangLuongs.ToList();
        }
        public static QuaTrinhTangLuong Single(int id)
        {
            return QTTangLuongs.SingleOrDefault(x => x.ID == id);
        }
        public static int Add(QuaTrinhTangLuong entity)
        {
            using (var db = new DataContext())
            {
                object rs = db.InsertWithIdentity(entity);
                return int.Parse(rs.ToString());
            }
        }
        public static int Update(QuaTrinhTangLuong entity)
        {
            using (var db = new DataContext())
            {
                return db.Update(entity);
            }
        }
        public static int Delete(int id)
        {
            return QTTangLuongs.Delete(x => x.ID == id);
        }
    }
}